#!/usr/bin/env python 
# -*- coding:utf-8 -*-
import numpy as np
import pandas as pd
import torch




tdata = pd.read_csv('course_1w.csv')
train_data = tdata.copy()
# 把用户id和项目id的类别换成枚举类
train_data = train_data.astype({'user_id': 'category', 'course_id': 'category'})

# 实现了绝对id到相对id的映射
train_user_ids = torch.LongTensor(train_data['user_id'].cat.codes.values)
train_item_ids = torch.LongTensor(train_data['course_id'].cat.codes.values)
new_user_id = train_user_ids.tolist()
new_item_id = train_item_ids.tolist()


item_dict = dict(zip(train_data['course_id'].values.tolist(),new_item_id))
print(item_dict)

train_data['user_id'] = new_user_id
train_data['course_id'] = new_item_id
train_data.drop(['update_time','dislike_status','classify_name'],axis=1,inplace=True)
train_data.to_csv('fslData.csv',index=None)

all_inter = pd.DataFrame()
all_inter['user_id'] = train_data['user_id']
all_inter['course_id'] = train_data['course_id']
all_inter.to_csv('all_inter.csv',index=None)

all = pd.DataFrame()
all['user_id'] = train_data['user_id']
all['course_id'] = train_data['course_id']
value_list = train_data['duration'].values.tolist()
value_list = [1 for i in value_list]
all['interact'] = value_list
all.to_csv('all.csv',index=None)